package com.cdream.basic.algorithm.leetcode.array;

/**
 * @author cdream
 * @date 2022/2/21
 */
public class Question838 {
    public String pushDominoes(String dominoes) {
        char[] arr = dominoes.toCharArray();
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != '.') {
                continue;
            }
            char left;
            if (i == 0) {
                left = '.';
            } else {
                left = arr[i - 1];
            }
            char r = '.';
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] == '.') {
                    continue;
                }
                r = arr[j];
                break;
            }

            if ((left == 'R' && r == 'L') || (left == '.' && r == '.') || (left == 'L' && r == 'R') || (left == 'L' && r == '.') || (left == '.' && r == 'R')) {
                arr[i] = '.';
            }
            if ((left == 'R' && r == 'R') || (left == 'R' && r == '.')) {
                arr[i] = 'R';
            }
            if ((left == 'L' && r == 'L') || (left == '.' && r == 'L')) {
                arr[i] = 'L';
            }
        }
        return new String(arr);
    }

    public static void main(String[] args) {
        new Question838().pushDominoes(".L.R...LR..L..");
    }
}
